<div data-controller="logs" data-logs-url-value="<%= request.original_url %>">
  <%= link_to back_path, class: "btn btn-ghost btn-sm", data: { turbo: "false" } do %>
    <iconify-icon icon="lucide:chevron-left"></iconify-icon> Back
  <% end %>
  <div class="flex space-x-2 items-center mb-2">
    <h4 class="text-md font-medium"><%= params[:id] %></h4>
    <div class="badge badge-success">• LIVE</div>
  </div>
  <% if defined?(error) && error.present? %>
    <div class="alert alert-warning my-5">
      <iconify-icon icon="lucide:alert-triangle" height="20"></iconify-icon>
      <span><%= error %></span>
    </div>
  <% end %>
  <div class="bg-gray-900 text-gray-100 rounded-lg shadow-lg">
    <div class="overflow-auto h-96 bg-gray-800 p-2 rounded" data-logs-target="container">
      <pre class="text-sm font-mono whitespace-pre-wrap" id="logs"><%= ansi_to_tailwind(logs.force_encoding("UTF-8")).html_safe || "No logs yet..." %></pre>
    </div>
  </div>

  <div class="flex space-x-2 items-center mt-8">
    <h4 class="text-lg font-medium">Start Up Logs</h4>
  </div>
  <div class="bg-gray-900 text-gray-100 rounded-lg shadow-lg mt-4">
    <div class="overflow-auto h-48 bg-gray-800 p-2 rounded">
      <pre class="text-sm font-mono whitespace-pre-wrap" id="startup-logs"><%
        event_logs = pod_events.map do |event|
          timestamp_str = event.lastTimestamp || event.firstTimestamp || event.metadata.creationTimestamp
          timestamp = Time.parse(timestamp_str)
          "[#{timestamp.strftime('%Y-%m-%d %H:%M:%S')}] #{event.reason}: #{event.message}"
        end.join("\n")
        %><%= ansi_to_tailwind(event_logs.force_encoding("UTF-8")).html_safe %></pre>
    </div>
  </div>
</div>
